<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core" template="/mainTemplate.xhtml">

    <ui:define name="content">
        <h:form id="projectsForm">

            <p:toolbar id="projectToolbar" style="margin-top:20px; margin-bottom:5px">
                <p:toolbarGroup align="left">
                    <p:commandButton value="Добавить"
                                     action="#{projectBean.addProject()}" style="font-size: 85% !important"/>
                    <p:commandButton value="Редактировать" action="#{projectBean.editProject()}"
                                     update=":editProjectDialogForm:editProjectDialog"
                                     style="font-size: 85% !important"/>
                    <p:commandButton value="Просмотреть"
                                     action="#{projectBean.viewProject()}" style="font-size: 85% !important"/>
                </p:toolbarGroup>
            </p:toolbar>

            <p:dataTable id="projectTable" var="project" value="#{projectBean.projectList}"
                         rowKey="#{project.name}" selection="#{projectBean.selectedProject}"
                         selectionMode="single">

                <p:column headerText="Название">
                    <h:outputText value="#{project.name}" />
                </p:column>

                <p:column headerText="Заказчик">
                    <h:outputText value="#{projectBean.getCustomer(project.id)}" />
                </p:column>

                <p:column headerText="Дата начала строительства">
                    <h:outputText value="#{projectBean.getProjectStartDate(project.id)}" />
                </p:column>

                <p:column headerText="Дата окончания строительства">
                    <h:outputText value="#{projectBean.getProjectEndDate(project.id)}" />
                </p:column>

                <p:column headerText="Стоимость заказа">
                    <h:outputText value="#{projectBean.getProjectTotal(project.id)}" />
                </p:column>

            </p:dataTable>

        </h:form>
        <h:form id="addProjectDialogForm">
            <p:dialog id="addProjectDialog" widgetVar="addProjectDialog" header="Создание проекта" modal="true"
                    resizable="true" height="500">
                <ui:include src="dialogs/addProject.xhtml"/>
            </p:dialog>
            <script type="text/javascript">
                function handleCreateProjectRequest(xhr, status, args) {
                    if(args.validationFailed || !args.saveProject) {
                        jQuery('#addProjectDialog').effect("shake", { times:3 }, 100);
                    } else {
                        addProjectDialog.hide();
                    }
                }
            </script>
        </h:form>
        <h:form id="editProjectDialogForm">
            <p:dialog id="editProjectDialog" widgetVar="editProjectDialog" header="Изменение проекта" modal="true"
                      resizable="true" height="500" dynamic="true">
                <ui:include src="dialogs/editProject.xhtml"/>
            </p:dialog>
            <script type="text/javascript">
                function handleEditProjectRequest(xhr, status, args) {
                    if(args.validationFailed || !args.saveProject) {
                        jQuery('#editProjectDialog').effect("shake", { times:3 }, 100);
                    } else {
                        editProjectDialog.hide();
                    }
                }
            </script>
        </h:form>
    </ui:define>
</ui:composition>